#pragma once
#include "where.h"

#define Tnline template<typename T> inline

class Update 
{
protected:
	string  _table;
	sstream _value;
	Where   _where;
public:
	inline Update(const string& t);
	inline Update& clear(void);
	Tnline Update& set(const string&, T v);
	inline string data(void)const;
	inline Where& where(void);
};

inline Update::Update(const string& t):_table(t)
{
}
inline Update& Update::clear(void)
{
	_value.str("");
	_where.clear();
	return *this;
}
inline Where& Update::where(void)
{
	return _where;
}
inline string Update::data(void)const
{
	return "UPDATE " + _table + " SET " + _value.str() + _where.data();
}
Tnline Update& Update::set(const string& name, T value)
{
	if(_value.tellp() > 0)
	{
		_value << ",";
	}
	_value << name << "='" << value << "'";
	return *this;
}
template<> inline Update& Update::set(const string& name, const char value)
{
	return this->set(name, 0x0ff & value);
}
template<> inline Update& Update::set(const string& name, const signed char value)
{
	return this->set(name, 0x0ff & value);
}
template<> inline Update& Update::set(const string& name, const unsigned char value)
{
	return this->set(name, 0x0ff & value);
}
#undef Tnline
